package com.gisuni.sddc.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.json.JSONArray;
import org.json.JSONObject;
import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.nutz.dao.sql.SqlCallback;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;

@IocBean
public class CopyOfLandStatisticsDao {

	@Inject
	private Dao dao;  //=OdbcCommon.getGISDao();
	

	public String queryAndStatisticsLandByTeam(String selectSql){
		Sql sql = Sqls.create(selectSql);
	    sql.setCallback(new SqlCallback() {
			public Object invoke(Connection conn, ResultSet rs, Sql sql)
					throws SQLException {
				JSONArray result=new JSONArray();
				int numberOfColumns = rs.getMetaData().getColumnCount();
				
			     while (rs.next()){
			    	 JSONObject ret=new JSONObject();
			    	 
						
						
						// 遍历查询结果字段
						for (int i = 0; i < numberOfColumns; i++) {
							Object obj = rs.getString(i + 1);
							ret.put(rs.getMetaData().getColumnName(i+1).trim(), obj);
						}
//			    	 	ret.put("company", rs.getString("COMPANY"));
////			    	 	if (rs.findColumn("DEPARTMENT") > 0 ){
////			    	 		ret.put("department", rs.getString("DEPARTMENT"));
////			    	 	}
////			    	 	if (rs.findColumn("TEAM") > 0 ){
////			    	 		ret.put("team", rs.getString("TEAM"));
////			    	 	}
////			    	 	if (rs.findColumn("TEAMLEADER") > 0 ){
////			    	 		 ret.put("teamleader",  rs.getString("TEAMLEADER"));
////			    	 	}
////			    	 	if (rs.findColumn("GNUM") > 0 ){
//			    	 		 ret.put("gnum", rs.getString("GNUM"));
////			    	 	}
//			    	 ret.put("pnum",rs.getString("PNUM"));
//			    	 ret.put("zhibiao", rs.getString("ZHIBIAO"));
//			    	 ret.put("wcd", rs.getString("WCD"));
			    	 result.put(ret);
			     }
				return result.toString();
			}
		});
	    dao.execute(sql);
	    return  sql.getObject(String.class);
	}
}
